package van.planifolia.demo02;

import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.util.Arrays;

/**
 * Created by Intellij IDEA<br>
 *
 * @author Planifolia.Van
 * @version 1.0
 * @date 2022/10/27 17:43
 */
public class ReflexOperationFields {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        Class<People> peopleClass = People.class;
        Class<Worker> workerClass = Worker.class;
        People people = new People();
        Worker worker = new Worker();

        Arrays.stream(workerClass.getFields()).forEach(System.out::println);
        Field name = peopleClass.getField("name");
        System.out.println(name);

        Arrays.stream(peopleClass.getDeclaredFields()).forEach(System.out::println);
        Field wages = workerClass.getDeclaredField("wages");
        System.out.println(wages);

        name.set(people,"123");
        System.out.println(name.get(people));
        wages.setAccessible(true);
        wages.set(worker,new BigDecimal(12345));
        System.out.println(wages.get(worker));


    }
}
class People{
    private String age;
    public String name;
}
class Worker extends People{
    private BigDecimal wages;
    public String address;
}